package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.vendor;
import com.ruoyi.system.service.IvendorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商详情Controller
 * 
 * @author ruoyi
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/context/context")
public class vendorController extends BaseController
{
    @Autowired
    private IvendorService vendorService;

    /**
     * 查询供应商详情列表
     */
    @PreAuthorize("@ss.hasPermi('context:context:list')")
    @GetMapping("/list")
    public TableDataInfo list(vendor vendor)
    {
        startPage();
        List<vendor> list = vendorService.selectvendorList2(vendor);
        return getDataTable(list);
    }

    /**
     * 导出供应商详情列表
     */
    @PreAuthorize("@ss.hasPermi('context:context:export')")
    @Log(title = "供应商详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, vendor vendor)
    {
        List<vendor> list = vendorService.selectvendorList(vendor);
        ExcelUtil<vendor> util = new ExcelUtil<vendor>(vendor.class);
        util.exportExcel(response, list, "供应商详情数据");
    }

    /**
     * 获取供应商详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('context:context:query')")
    @GetMapping(value = "/{vaId}")
    public AjaxResult getInfo(@PathVariable("vaId") Long vaId)
    {
        return success(vendorService.selectvendorByVaId(vaId));
    }

    /**
     * 新增供应商详情
     */
    @PreAuthorize("@ss.hasPermi('context:context:add')")
    @Log(title = "供应商详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody vendor vendor)
    {
        return toAjax(vendorService.insertvendor(vendor));
    }

    /**
     * 修改供应商详情
     */
    @PreAuthorize("@ss.hasPermi('context:context:edit')")
    @Log(title = "供应商详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody vendor vendor)
    {
        return toAjax(vendorService.updatevendor(vendor));
    }

    /**
     * 删除供应商详情
     */
    @PreAuthorize("@ss.hasPermi('context:context:remove')")
    @Log(title = "供应商详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vaIds}")
    public AjaxResult remove(@PathVariable Long[] vaIds)
    {
        return toAjax(vendorService.deletevendorByVaIds(vaIds));
    }
}
